/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package smartgrid;

import org.orm.PersistentException;
public class FaceBookAccountProcessor {
	private int ID;
	
	private String UId;
	
	private String Nome;
	
	private String EMail;
	
	private boolean Enable;
	
	private String action="";
	
	public void setID(int value) {
		this.ID = value;
	}
	
	public int getID() {
		return ID;
	}
	
	/**
	 * Identificador da conta do facebook.
	 */
	public void setUId(String value) {
		this.UId = value;
	}
	
	public String getUId() {
		return UId == null ? "" : UId;
	}
	
	/**
	 * Nome do titular da conta do facebook.
	 */
	public void setNome(String value) {
		this.Nome = value;
	}
	
	public String getNome() {
		return Nome == null ? "" : Nome;
	}
	
	/**
	 * E-mail do titular da conta do facebook.
	 */
	public void setEMail(String value) {
		this.EMail = value;
	}
	
	public String getEMail() {
		return EMail == null ? "" : EMail;
	}
	
	public void setEnable(boolean value) {
		this.Enable = value;
	}
	
	public boolean getEnable() {
		return Enable;
	}
	
	public String getAction() {
		return action;
	}
	
	public void setAction(String action) {
		this.action = action;
	}
	
	public String process() {
		String result = "Unexcepted result";
		if (action.equals("search")) {
			smartgrid.FaceBookAccount _faceBookAccount = smartgrid.FaceBookAccount.loadFaceBookAccountByORMID(getID());
			if (_faceBookAccount!= null) {
				copyFromBean(_faceBookAccount);
				result = "Search success";
			}
			else {
				result = "Search failed";
			}
		}
		else if(action.equals("insert"))  {
			try {
				smartgrid.FaceBookAccount _faceBookAccount = smartgrid.FaceBookAccount.createFaceBookAccount();
				copyToBean(_faceBookAccount);
				if (_faceBookAccount.save()) {
					result = "Insert success";
				}
				else {
					result = "Insert failed";
				}
			}
			catch (Exception e) {
				result = "Insert error: " + e.toString();
			}
		}
		else if (action.equals("update")) {
			smartgrid.FaceBookAccount _faceBookAccount= smartgrid.FaceBookAccount.loadFaceBookAccountByORMID(getID());
			if (_faceBookAccount != null) {
				copyToBean(_faceBookAccount);
				if (_faceBookAccount.save()) {
					result = "Update success";
				}
				 else {
					result = "Update failed";
				}
			}
			 else  {
				result = "Update failed";
			}
			
		}
		else if (action.equals("delete")) {
			smartgrid.FaceBookAccount _faceBookAccount = smartgrid.FaceBookAccount.loadFaceBookAccountByORMID(getID());
			if (_faceBookAccount != null && _faceBookAccount.deleteAndDissociate()) {
				result = "Delete success";
			}
			else {
				result = "Delete failed";
			}
		}
		else if (action.equals("")) {
			result = "";
		}
		action = "";
		return result;
	}
	
	private void copyFromBean(smartgrid.FaceBookAccount _faceBookAccount) {
		setUId(_faceBookAccount.getUId());
		setNome(_faceBookAccount.getNome());
		setEMail(_faceBookAccount.getEMail());
		setEnable(_faceBookAccount.getEnable());
		setID(_faceBookAccount.getORMID());
	}
	
	private void copyToBean(smartgrid.FaceBookAccount _faceBookAccount) {
		_faceBookAccount.setUId(getUId());
		_faceBookAccount.setNome(getNome());
		_faceBookAccount.setEMail(getEMail());
		_faceBookAccount.setEnable(getEnable());
	}
	
}

